package com.chzc.fm.duotin.utils;

/**
 * Created by BillSinla on 2016/6/13.
 */
public class NumberUtil {

    /*
    * 计算人数的方法
    * */
    public static String countNumber(int number){
        float temp;
        if( number > 10000 ){
            if(number / 10000 > 99) {
                return "99w+";
            }else{
                temp = (float) (number / 10000.0);
                return "" + Float.parseFloat(String.format("%.1f", temp)) + "w";
            }
        }else if(number > 1000){
            temp = (float)(number/1000.0);
            return "" + Float.parseFloat(String.format("%.1f", temp)) + "k";
        }else{
            return "" + number;
        }
    }

    /**
     * 计算占用的空间大小
     */
    public static String countSpace(long num){
        double temp = num;
        if( temp > 1024 ){
            temp = temp / 1024.0;
            if( temp > 1024){
                temp = temp / 1024.0;
                if( temp > 1024){
                    temp = temp / 1024.0;
                    return "" + Double.parseDouble(String.format("%.1f", temp)) + "GB";
                }else{
                    return "" + Double.parseDouble(String.format("%.1f", temp)) + "MB";
                }
            }else{
                return "" + Double.parseDouble(String.format("%.1f", temp)) + "KB";
            }
        }else{
            return "" + num + "B";
        }
    }
}
